#cmake的目标&&设置cmake目标属性的值

cmake_minimum_required(VERSION 3.10)
project(course_03)

set(CMAKE_CXX_STANDARD 11)  # 将 C++ 标准设置为 C++ 11
set(CMAKE_CXX_STANDARD_REQUIRED ON)  # C++ 11 是强制要求，不会衰退至低版本
set(CMAKE_CXX_EXTENSIONS OFF)  # 禁止使用编译器特有扩展

if(NOT CMAKE_BUILD_TYPE)
    message(WARNING "NOT SET CMAKE_BUILD_TYPE")
    set(CMAKE_BUILD_TYPE "Release")
endif()

#使用aux_source_directory获取所有源文件,src 目录
aux_source_directory(src SRC)
message("SRC内容是->${SRC}" )#SRC内容 src/add.cpp;src/main.cpp;src/sub.cpp

set(INCLUDE "include")

#add_executable 生成可执行文件run
add_executable(run ${SRC})
#add_library 生成共享库或者静态库目标
add_library(math SHARED ${SRC})  #生成共享库math
add_library(maths STATIC ${SRC})  #生成静态库static

#为目标添加文件包含路径
target_sources(run PRIVATE ${SRC})
target_include_directories(run PRIVATE ${INCLUDE})

##################设置目标属性值####################
#[[

#设置包含路径
target_include_directories(target_name PUBLIC include_dir)
#设置编译时预定义的宏
target_compile_definitions(target_name PUBLIC definition)
#设置编译选项
target_compile_options(target_name PUBLIC option)
#设置链接的库
target_link_libraries(target_name library_name)
#设置源文件
target_sources(target_name PUBLIC source_file)
#设置编译C++特性
target_compile_features(target_name PUBLIC feature)

]]

#################获取目标属性的值####################
#[[

get_target_property(include_dir target_name INCLUDE_DIRECTORIES)
get_target_property(definition target_name COMPILE_DEFINITIONS)
get_target_property(option target_name COMPILE_OPTIONS)
get_target_property(library_name target_name LINK_LIBRARIES)
get_target_property(source_file target_name SOURCES)
get_target_property(feature target_name COMPILE_FEATURES)

]]


#学习来源：https://zhuanlan.zhihu.com/p/655302131
